<?php
//连接数据库
$dsn = "sqlsrv:Server=localhost;Database=Task";
$db = new PDO($dsn, "sa", "123456");
$sql = 'select * from Task order by TaskId desc';
$result = $db->query($sql);
$TaskList = $result->fetchAll(PDO::FETCH_ASSOC);
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>任务列表</title>
    <link rel="stylesheet" type="text/css" href="css/main.css" />
    <script type="text/javascript">
        window.onload=function () //加载全部网页内容
        {
            var obtn = document.getElementById('btn'); //获取全选标签
            var ainput = document.getElementsByTagName('input');//获取全部input标签即获取全部复选框
            var i = 0;
            obtn.onclick=function ()//点击全部标签要执行下面事件
            {
                for (i=0;i<ainput.length;i++)
                {
                    ainput[i].checked=true;//重复选择复选框
                }
            }
        }
        function firm() {
            //利用对话框返回的值 （true 或者 false）
            if (confirm("你确定删除吗？")) {
                alert("点击了确定");
                return true;
            }
            else {
                alert("点击了取消");
                return false;
            }

        }
    </script>
</head>
<body>
<div id="container">
    <div id="login_info">
        欢迎你：admin
        <a href="logout.html">退出登录</a>
    </div>
    <div id="choose_div">
        <button id="btn">全选</button>
        <a id="multi_delete" href="delete.php?task_id=<?php echo $TaskList['TaskId'] ?>" onclick=" return firm()"  >删除选中任务</a>

        <a id="add" href="task_add.php" style="float: right">增加任务</a>
    </div>
    <table class="list">
        <tbody>
        <tr>
            <th></th>
            <th>任务id</th>
            <th>任务名称</th>
            <th>任务状态</th>
            <th>创建时间</th>
            <th>修改时间</th>
            <th>操作</th>
        </tr>
        <?php foreach ($TaskList as $key=>$value): ?>
        <tr>
            <td><input type="checkbox"  name="<?php echo $value['TaskId']  ?>" ></td>
            <td>
                <?php  echo $value['TaskId']?>
            </td>
            <td>
                <?php echo $value['TaskName']?>
            </td>
            <td>
                <?php
                if ($value['TaskStatus']==1){
                    echo '新创建';
                }else if ($value['TaskStatus']==2){
                    echo '进行中';
                }else if ($value['TaskStatus']==3){
                    echo '已完成';
                }

                ?>
            </td>
            <td>
                <?php
                echo $value['TaskCreateTime'];
                ?>
            </td>
            <td>
                <?php
                echo $value['TaskUpdateTime'];
                ?>
            </td>
            <td>
                <a class="update_ing" href="task_update.php?task_id=<?php echo $value['TaskId']?>">详情</a>
            </td>
        </tr>
        <?php endforeach; ?>
        </tbody>
    </table>
</div>
</body>
</html>

